//
// Copyright (C) 2011 Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.101
//#include "stdafx.h"
#include "Bilinear.h"
using namespace Cephei::QL::Math::Interpolations;
#include <gen/QL/Math/Interpolations/Interpolation2D.h>
#undef HANDLE
#undef ABSTRACT
#undef STRUCT
Cephei::QL::Math::Interpolations::CBilinear::CBilinear (boost::shared_ptr<QuantLib::Bilinear>& childNative, Object^ owner) 
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phBilinear = NULL;
#endif
	_ppBilinear = &childNative;
    
}
Cephei::QL::Math::Interpolations::CBilinear::CBilinear (QuantLib::Bilinear& childNative, Object^ owner) 
{
#ifdef HANDLE
	_phBilinear = NULL;
#endif
	_ppBilinear = new boost::shared_ptr<QuantLib::Bilinear> (&childNative);
    
    _BilinearOwner = owner;
    
}

Cephei::QL::Math::Interpolations::CBilinear::CBilinear (CBilinear^ copy) 
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phBilinear = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppBilinear = new boost::shared_ptr<QuantLib::Bilinear> (copy->GetShared());
        
    }
}
Cephei::QL::Math::Interpolations::CBilinear::CBilinear (System::Type^ t) 
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phBilinear = NULL;
#endif
	if (!t->IsSubclassOf(CBilinear::typeid))
		throw gcnew Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Math::Interpolations::CBilinear::CBilinear (QuantLib::Handle<QuantLib::Bilinear>& childNative, Object^ owner)  
{
	_pSpinlock = new boost::detail::spinlock ();
	_phBilinear = &childNative;
	_ppBilinear = &static_cast<boost::shared_ptr<QuantLib::Bilinear>>(childNative.currentLink());
    
    _BilinearOwner = owner;
}
Cephei::QL::Math::Interpolations::CBilinear::CBilinear (QuantLib::Handle<QuantLib::Bilinear> childNative)  
{
	_pSpinlock = new boost::detail::spinlock ();
	_phBilinear = &childNative;
	_ppBilinear = &static_cast<boost::shared_ptr<QuantLib::Bilinear>>(childNative.currentLink());
    
}
#endif
#ifdef STRUCT
Cephei::QL::Math::Interpolations::CBilinear::CBilinear (QuantLib::Bilinear childNative)  
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phBilinear = NULL;
#endif
	_ppBilinear = new boost::shared_ptr<QuantLib::Bilinear> (new QuantLib::Bilinear (childNative));
    
}
#endif

Cephei::QL::Math::Interpolations::CBilinear::~CBilinear ()
{
	if (_pSpinlock != NULL)
    {
        delete _pSpinlock;
        _pSpinlock = NULL;
    }
    if (_ppBilinear != NULL)
    {
	    delete _ppBilinear;
        _ppBilinear = NULL;
    }
}
Cephei::QL::Math::Interpolations::CBilinear::!CBilinear ()
{
	if (_pSpinlock != NULL)
    {
        delete _pSpinlock;
    }
    if (_ppBilinear != NULL)
    {
	    delete _ppBilinear;
    }
}
QuantLib::Bilinear& Cephei::QL::Math::Interpolations::CBilinear::GetReference ()
{
    if (_ppBilinear == NULL) throw gcnew NativeNullException ();
	return **_ppBilinear;
}
boost::shared_ptr<QuantLib::Bilinear>& Cephei::QL::Math::Interpolations::CBilinear::GetShared ()
{
    if (_ppBilinear == NULL) throw gcnew NativeNullException ();
	return *_ppBilinear;
}
QuantLib::Bilinear* Cephei::QL::Math::Interpolations::CBilinear::GetPointer ()
{
    if (_ppBilinear == NULL) throw gcnew NativeNullException ();
	return &**_ppBilinear;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::Bilinear>& Cephei::QL::Math::Interpolations::CBilinear::GetHandle ()
{
	if (_phBilinear == NULL)
	{
		_phBilinear = new Handle<QuantLib::Bilinear> (*_ppBilinear);
	}
	return *_phBilinear;
}
#endif
bool Cephei::QL::Math::Interpolations::CBilinear::HasNative () 
{
	return (_ppBilinear != NULL);
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

